<template>
    <input type="text" @keyup.enter="addTodo" v-model="title">
</template>

<script>
    import {nanoid} from "nanoid"
    export default {
        name : "MyHeader",
        data() {
            return {
                title: '',
            };
        },
        //props的优先级比methods高。
        props:["receive"],
        methods:{
            // addTodo(){
            //     console.log(this.title)
            // }
            addTodo(){
                if(!this.title) return
                const todoObj = {
                    id:nanoid(),
                    title:this.title,
                    done:false,
                }
                this.receive(todoObj)
                this.title = ''
            }
        }
    }
</script>

<style scoped>

</style>
